package com.xexun.gpstracker.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.text.Editable;
import android.util.AttributeSet;
import android.widget.EditText;

import com.xexun.gpstracker.channel.R;
import com.xexun.gpstracker.util.CommUtil;

/**
 * Created by HH
 * Date: 2015/12/1 0001
 * Time: 下午 5:57
 */
public class PrettyEditText extends EditText {
    private String separator;
    private int[] pos;

    public PrettyEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.PrettyEditTextAttr);
        separator = typedArray.getString(R.styleable.PrettyEditTextAttr_separator);
        String ps = typedArray.getString(R.styleable.PrettyEditTextAttr_position);
        if (ps == null) {
            pos = new int[0];
        } else {
            String[] sa = ps.split(",| ");
            pos = new int[sa.length];
            for (int i = 0; i < sa.length; i++) {
                pos[i] = CommUtil.toInteger(sa[i], -1);
            }
        }
        typedArray.recycle();
    }

    @Override
    protected void onDraw(Canvas canvas) {
//        Editable edt = super.getText();
//        String str = CommUtil.prettyString(edt.toString(), separator, true, pos);
//        edt.setFilters(new InputFilter[0]);
//        edt.clearSpans();
//        edt.clear();
//        edt.append(str);
//        setSelection(str.length());
        super.onDraw(canvas);
    }

    @Override
    public Editable getText() {
//        Editable edt = super.getText();
//        String str = edt.toString();
//        edt.setFilters(new InputFilter[0]);
//        edt.clearSpans();
//        edt.clear();
//        return edt.append(CommUtil.trimSeprator(str, separator));
        return super.getText();
    }
}
